package com.ctrl.riveradministrator.mvp.view.activity.illegal_report;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.ctrl.riveradministrator.R;

import java.util.List;

public class GridViewAdapter extends BaseAdapter {

    private Context mContext;
    private List<String> mList;
    private LayoutInflater inflater;

    public GridViewAdapter(Context mContext, List<String> mList) {
        this.mContext = mContext;
        this.mList = mList;
        inflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        int count = mList == null ? 1 : mList.size() + 1;
        if (count > 1) {//最多选择5张图片
            return mList.size();
        } else {
            return count;
        }
    }

    @Override
    public Object getItem(int i) {
        return mList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @SuppressLint("ViewHolder")
    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        view = inflater.inflate(R.layout.grid_item, viewGroup,false);
        ImageView iv = view.findViewById(R.id.pic_iv);
        if (i < mList.size()) {
            //代表+号之前的需要正常显示图片
            String picUrl = mList.get(i); //图片路径
            Glide.with(mContext).load(picUrl).into(iv);
        } else {
            iv.setImageResource(R.mipmap.zj);//最后一个显示加号图片
        }
        return view;
    }
}
